let jwt = require("jsonwebtoken")

module.exports = {
  //生成签名
  sign: ({ username, _id }) => {
    return jwt.sign({ username, _id }, "CS-2001", { expiresIn: 60 * 60 * 24 })
  },
  //校验签名
  verify: token => {
    return new Promise((resolve, reject) => {
      jwt.verify(token, "CS-2001", (err, decode) => {
        if (!err) {
          resolve(decode)
        } else {
          reject(err.message)
        }
      })
    })
  }
}